package com.itany.corejava.code09_集合.zuoye2;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月22日 17:26
 */

import java.util.*;

/**
 * 创建一个Person类，有name、address、salary
 * 提示用户输入4个用户的名字、地址、工资存入到ArrayList
 * 先按名字长度大小排，名字长度相同的情况下吗，按照工资从高到低排
 *
 *
 */
public class Test03_练习 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        List<Person> list=new ArrayList<>();
       for(int i=1;i<=4;i++){
           System.out.print("请同时输入该用户的名字、地址、工资：");
           String str=sc.next();
           String[] arrs=str.split("、");
           Person person=new Person(arrs[0],arrs[1],Double.parseDouble(arrs[2]));
           list.add(person);

       }
        System.out.println(list);

        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person p1, Person p2) {
                if(p1.getName().length()>p2.getName().length()){
                    return -1;
                }else if(p1.getName().length()<p2.getName().length()){
                    return 1;
                }else{
                    if(p1.getSalary()>p2.getSalary()){
                        return -1;
                    }else if(p1.getSalary()<p2.getSalary()){
                        return 1;
                    }else{
                        return 0;
                    }
                }

            }
        });

        System.out.println(list);

    }
}

class Person{
    private String name;
    private String address;
    private double salary;

    public Person(String name, String address, double salary) {
        this.name = name;
        this.address = address;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", salary=" + salary +
                '}';
    }
}